version 16
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.XX OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************/

/* PRELIMINARIES */

#d				;
matrix 			input table=(0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0\
							 0,0,0,0\0,0,0,0);
#d				cr
use				"$project_data\ITRM_Dislo_Unique_Top1000_Corporate_Master.dta", clear
g				treat=(rank>80 & rank<=120)
keep			if year==2010 | year==2011

/* TAXABLE INCOME */

g				logz=log(taxableinc)
local			i=1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean logz if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test logz@1.treat=logz@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* TAX PAID ON TAXABLE INCOME */

g				logtz=log(r9201)
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean logtz if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test logtz@1.treat=logtz@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* FINAL TAX */

g				logtf=log(r9202)
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean logtf if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test logtf@1.treat=logtf@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* TOP CITY */

preserve
drop			if it_office_id==.
g				trait=(it_office_id==1 | it_office_id==6 | 					///
				it_office_id==10 | it_office_id==16 | it_office_id==66 			///
				| it_office_id==70 | it_office_id==74 | it_office_id==97 		///
				| it_office_id==9 | it_office_id==20)
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3
restore

/* FILING DATE */

preserve
drop			if return_filing_date==.
g 				double fdate=dofc(return_filing_date)
g				trait=0
qui				sum fdate if year==2011,d
replace			trait=1 if year==2011 & fdate<=r(p50)
qui				sum fdate if year==2010,d
replace			trait=1 if year==2010 & fdate<=r(p50)
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3
restore

/* AGE */

preserve
drop			if birth_foundation_date==.
g 				double bdate=dofc(birth_foundation_date)
g 				byear=year(bdate)
g 				age=2016-byear								
qui				sum age,d
g				trait=(age<=r(p50))		
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3
restore

/* PUBLIC LIMITED COMPANY */

g				trait=public==1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* FOREIGN OWNED */

drop			trait
g 				trait=isforeign_controlled==1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* BANK */

drop			trait
g				trait=bank==1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* FOOD */

drop			trait
g 				fd1=strpos(business_group, "food")
g				trait=fd1>0
drop			fd1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* TEXTILE */

drop			trait
g				trait=textile==1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* PHARMA */

drop			trait
g 				phar1=strpos(business_group,"pharma")
g				trait=phar1>0
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* CONSTRUCTION */

drop			trait
g				trait=const==1
local			j=1
forvalues		y=2011(-1)2010 {
qui				mean trait if year==`y', over(treat) 
matrix			b=e(b)
matrix			se=e(V)
qui				test trait@1.treat=trait@0.treat
matrix			table[`i',`j']=b[1,2]
matrix			table[`i'+1,`j']=sqrt(se[2,2])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
matrix			table[`i',`j']=b[1,1]
matrix			table[`i'+1,`j']=sqrt(se[1,1])
matrix			table[`i'+2,`j']=r(p)
local			j=`j'+1
}
local			i=`i'+3

/* EXPORTING THE TABLE */ 

svmat 			table
keep			tab*
keep			if _n<=39
g				c11=""
replace			c11="1. Taxable Income" in 1
replace			c11="2. Tax Paid on Taxable Income" in 4
replace			c11="3. Final Tax Paid" in 7
replace			c11="4. Major city" in 10
replace			c11="5. Early filer" in 13
replace			c11="6. Young Firm" in 16 
replace			c11="7. Public Limited" in 19
replace			c11="8. Foreign Owned" in 22
replace			c11="9. Bank" in 25
replace			c11="10. Food" in 28
replace			c11="11. Textile" in 31
replace			c11="12. Pharma" in 34
replace			c11="13. Construction" in 37

forvalues 		c=1/4 {
g				c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(3)38 {
forvalues		c=1/4 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		r=3(3)39 {
forvalues		c=1/4 {
replace			c`c'="["+string(table`c',"%9.3f")+"]" in `r'
}
}
forvalues		s=1/6 {
g				s`s'="&"
}
g				l="\\"
order			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 l
browse			c11 s1 c1 s2 c2 s3 s4 c3 s5 c4 l




